package com.wing.common.utils;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * 分页结果对象
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class PageResult<T> extends Result implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 总数
     */
    private long count;

    /**
     * 数据
     */
    private List<T> data;

    private Boolean totalFlag;

    private BigDecimal currentTotal;

    private BigDecimal settingTotal;

    public PageResult(List<T> rows) {
        this.data = rows;
        this.count = rows.size();
        this.code = Code.SUCCESS.getCode();
        this.msg = Code.SUCCESS.getDesc();
    }

    public PageResult(Code code, List<T> rows) {
        this.data = rows;
        this.count = rows.size();
        this.code = code.getCode();
        this.msg = code.getDesc();
    }

    public PageResult(Code code, String msg, List<T> rows) {
        this.data = rows;
        this.count = rows.size();
        this.code = code.getCode();
        this.msg = msg;
    }

    public PageResult(List<T> rows, long total) {
        this.count = total;
        this.data = rows;
        this.code = Code.SUCCESS.getCode();
        this.msg = Code.SUCCESS.getDesc();
    }

    public PageResult(Code code, List<T> rows, long total) {
        this.count = total;
        this.data = rows;
        this.code = code.getCode();
        this.msg = code.getDesc();
    }

    public PageResult(Code code, String msg, List<T> rows, long total) {
        this.count = total;
        this.data = rows;
        this.code = code.getCode();
        this.msg = msg;
    }

}
